<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<body>
	<form id="addOrUpdate" method="post">
		<hidden id="hidden-params">
			<input id="btn_sub" type="hidden" onclick="submitForm()"/>
			<input id="parent_id" name="parentId" value="${m.parentId}" type="hidden"/>
		</hidden>
		<div>
	        <label for="type_tree_menu">上级类别:</label>
	        <input id="type_tree_menu" />   
	    </div>
	    <div>   
	        <label for="text">类别名称:</label>
	        <input type="text" id="text" name="text" value="${m.text}"/>   
	    </div>
	    <div>
        	<label for="level" class="ui-label">一级类别:</label>
        	<input type="radio" name="level" value="1" ${m.parentId==0?"checked":""}/>是
        	<input type="radio" name="level" value="0" ${m.parentId!=0?"checked":""}/>否
        </div>
	</form>
	<script type="text/javascript">
		var id = '${m.id}';
		//如果不为空，表示修改操作
		if(id!='' && id!=undefined){
			$('#hidden-params').append('<input name="id" value="${m.id}" type="hidden" />');
			$('#hidden-params').append('<input name="_method" value="put" type="hidden"/>');
		}
		$('#type_tree_menu').combotree({    
		    url: 'pageList',
		    required: true,
		    panelWidth:200,
		    loadFilter:function(data){
	        	return data.obj;
	        },
	        onLoadSuccess:function(row,data){
	        	var parentId = '${m.parentId}';
	        	if(parentId!='' && parentId!=undefined){
	        		$('#type_tree_menu').combotree('setValue',parentId);
	        	}
	        }
		});
		function submitForm(){
			$('#addOrUpdate').form('submit', {
			    url:'manage',
			    onSubmit: function(params){
			    	//获取上级菜单ID
			    	var t = $('#type_tree_menu').combotree('tree').tree('getSelected');	// 获取树对象选择的节点
			    	$('#parent_id').val(t.id);
			        return $(this).form('validate');
			    },
			    success:function(data){
			    	var info = eval('('+data+')');
			    	if(info.success){
				    	$(this).parent().dialog('destroy');
				    	$('#datagrid_list').treegrid('reload');	// 重新载入所有行
			    	}else{
				    	$.messager.alert('消息',info.msg);
			    	}
			    }
			});  
		}
	</script>
</body>